package controllers

import play.api.data._
import play.api.data.Forms._
import play.api.data.format.Formats._

/**
  * Created by yz on 2018/6/11
  */
class FormTool {

  case class ProjectNameData(projectName: String)

  val projectNameForm = Form(
    mapping(
      "projectName" -> text
    )(ProjectNameData.apply)(ProjectNameData.unapply)
  )

  case class ProjectData(projectName: String, describe: String)

  val projectForm = Form(
    mapping(
      "projectName" -> text,
      "describe" -> text
    )(ProjectData.apply)(ProjectData.unapply)
  )

  case class ProjectIdData(projectId: Int)

  val projectIdForm = Form(
    mapping(
      "projectId" -> number
    )(ProjectIdData.apply)(ProjectIdData.unapply)
  )

  case class DataDealData(normal: Option[String], delete: Option[String], replace: Option[String])

  val dataDealForm = Form(
    mapping(
      "normal" -> optional(text),
      "delete" -> optional(text),
      "replace" -> optional(text)
    )(DataDealData.apply)(DataDealData.unapply)
  )

  case class DeleteData(iqr: Double)

  val deleteForm = Form(
    mapping(
      "iqr" -> of(doubleFormat)
    )(DeleteData.apply)(DeleteData.unapply)
  )

  case class ReplaceData(replaceMethod: String, rate: Double, assignValue: String, kValue: Int)

  val replaceForm = Form(
    mapping(
      "replaceMethod" -> text,
      "rate" -> of(doubleFormat),
      "assignValue" -> text,
      "kValue" -> number
    )(ReplaceData.apply)(ReplaceData.unapply)
  )

  case class NormalData(normalMethod: String, rowName: String, colName: String, coefficient: Double)

  val normalForm = Form(
    mapping(
      "normalMethod" -> text,
      "rowName" -> text,
      "colName" -> text,
      "coefficient" -> of(doubleFormat)
    )(NormalData.apply)(NormalData.unapply)
  )

  val idForm = Form(
    single(
      "id" -> number
    )
  )

  case class GroupMessage(groupingName: String, groupNames: Seq[String],
                          sampleNames: Seq[String])

  val groupForm = Form(
    mapping(
      "groupingName" -> text,
      "groupNames" -> seq(text),
      "sampleNames" -> seq(text)
    )(GroupMessage.apply)(GroupMessage.unapply)
  )

  case class RelationData(id: Int, group1SampleNames: Seq[String], group2SampleNames: Seq[String])

  val relationForm = Form(
    mapping(
      "id" -> number,
      "group1SampleNames" -> seq(text),
      "group2SampleNames" -> seq(text)
    )(RelationData.apply)(RelationData.unapply)
  )

  case class GroupData(groupName: String)

  val groupNameForm = Form(
    mapping(
      "groupName" -> text
    )(GroupData.apply)(GroupData.unapply)
  )

  case class TTestData(groupName: String, paired: String, pCutoff: String, qCutoff: String, method: String,
                       logCutoff: String, varEqual: String)

  val tTestForm = Form(
    mapping(
      "groupName" -> text,
      "paired" -> text,
      "pCutoff" -> text,
      "qCutoff" -> text,
      "method" -> text,
      "logCutoff" -> text,
      "varEqual" -> text
    )(TTestData.apply)(TTestData.unapply)
  )

  case class BiosignerData(groupName: String, methodC: String, bootI: String, tierC: String, pvalN: String,
                           seedI: String, logCutoff: String)

  val biosignerForm = Form(
    mapping(
      "groupName" -> text,
      "methodC" -> text,
      "bootI" -> text,
      "tierC" -> text,
      "pvalN" -> text,
      "seedI" -> text,
      "logCutoff" -> text
    )(BiosignerData.apply)(BiosignerData.unapply)
  )

  case class OplsData(groupName: String, vipCutoff: String, log10: String, scaleC: String, permI: String, typeC: String,
                      parMahalC: String, parCexN: String, logCutoff: String,crossValI:String,orthoI:String)

  val oplsForm = Form(
    mapping(
      "groupName" -> text,
      "vipCutoff" -> text,
      "log10" -> text,
      "scaleC" -> text,
      "permI" -> text,
      "typeC" -> text,
      "parMahalC" -> text,
      "parCexN" -> text,
      "logCutoff" -> text,
      "crossValI" -> text,
      "orthoI" -> text
    )(OplsData.apply)(OplsData.unapply)
  )

  case class BarData(terms: Seq[String], datas: Seq[String])

  val barForm = Form(
    mapping(
      "terms" -> seq(text),
      "datas" -> seq(text)
    )(BarData.apply)(BarData.unapply)
  )

  case class KeggData(offerMethod: String, geneIdStr: String, log2FcStr: String, library: String, method: String, topMethod: String, reference: String)

  val keggForm = Form(
    mapping(
      "offerMethod" -> text,
      "geneIdStr" -> text,
      "log2FcStr" -> text,
      "library" -> text,
      "method" -> text,
      "topMethod" -> text,
      "reference" -> text
    )(KeggData.apply)(KeggData.unapply)
  )

  case class PcaData(method: String, sampleName: Seq[String], groupName: String, dtMethod: String, x: String, y: String)

  val pcaForm = Form(
    mapping(
      "method" -> text,
      "sampleName" -> seq(text),
      "groupName" -> text,
      "dtMethod" -> text,
      "x" -> text,
      "y" -> text
    )(PcaData.apply)(PcaData.unapply)
  )

  case class SampleNamesData(sampleNames: Seq[String])

  val sampleNamesForm = Form(
    mapping(
      "sampleNames" -> seq(text)
    )(SampleNamesData.apply)(SampleNamesData.unapply)
  )

  case class HClusterData(method: String, sampleDist: String, sampleCluster: String)

  val hClusterForm = Form(
    mapping(
      "method" -> text,
      "sampleDist" -> text,
      "sampleCluster" -> text
    )(HClusterData.apply)(HClusterData.unapply)
  )

  case class GeneIdStrData(geneIdStr: String)

  val geneIdStrForm = Form(
    mapping(
      "geneIdStr" -> text
    )(GeneIdStrData.apply)(GeneIdStrData.unapply)
  )

  case class HeatmapData(method: String, rowDist: String, colDist: String, rowCluster: String, colCluster: String)

  val heatmapForm = Form(
    mapping(
      "method" -> text,
      "rowDist" -> text,
      "colDist" -> text,
      "rowCluster" -> text,
      "colCluster" -> text
    )(HeatmapData.apply)(HeatmapData.unapply)
  )

  case class ExpressPatternData(sampleNameStr: String, method: String, cMethod: String, pTree: String, kTree: String,
                                k: String, sampleDist: String, sampleCluster: String)

  val expressPatternForm = Form(
    mapping(
      "sampleNameStr" -> text,
      "method" -> text,
      "cMethod" -> text,
      "pTree" -> text,
      "kTree" -> text,
      "k" -> text,
      "sampleDist" -> text,
      "sampleCluster" -> text
    )(ExpressPatternData.apply)(ExpressPatternData.unapply)
  )

  val groupingNameFom = Form(
    single(
      "groupingName" -> text
    )
  )

  case class RocData(groupingName: String, pGroup: String)

  val rocForm = Form(
    mapping(
      "groupingName" -> text,
      "pGroup" -> text
    )(RocData.apply)(RocData.unapply)
  )

  case class Log2FcStrData(log2FcStr: Option[String])

  val log2FcStrForm = Form(
    mapping(
      "log2FcStr" -> optional(text)
    )(Log2FcStrData.apply)(Log2FcStrData.unapply)
  )

  case class GeneIdData(geneId: String)

  val geneIdForm = Form(
    mapping(
      "geneId" -> text
    )(GeneIdData.apply)(GeneIdData.unapply)
  )

  case class DiffData(groupName: String)

  val diffForm = Form(
    mapping(
      "groupName" -> text
    )(DiffData.apply)(DiffData.unapply)
  )


}
